﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using albert.Model;

namespace albert.DB.SqlServer
{
    public class SqlServerHelper
    {
        
        public static string connectionStr = ConfigurationManager.ConnectionStrings["Customers"].ToString();

        public T Get<T>(int id)
        {
            string sql = @"Select a,b,c from user";

            using (SqlConnection conn = new SqlConnection())
            {
                SqlCommand command = new SqlCommand(sql, conn);
                conn.Open();
                SqlDataReader reader = command.ExecuteReader();
                if(reader.Read())
                {
                    Type type = typeof(User);
                    object oUser = Activator.CreateInstance(type);

                    foreach(var item in type.GetProperties())
                    {
                        Console.WriteLine("{0} {1}", item.Name, item.GetValue(oUser));

                        item.SetValue(oUser, reader[item.Name]);

                        Console.WriteLine("{0} {1}", item.Name, item.GetValue(oUser));
                    }
                }
            };

            return default(T);
        }
    
    }
}
